public class demo2 {
    final static long cout=2_0000_0000;
    public static void main(String[] args) {

        together();
        single();

    }

    //多线程执行任务1
    public static void together()  {
        long beginT=System.currentTimeMillis();
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                int a=0;
                for (int i = 0; i < cout; i++) {
                    a++;
                }
            }
        },"我的新线程1");
        thread.start();

        int b=0;
        for (int i = 0; i < cout; i++) {
            b++;
        }
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long endT=System.currentTimeMillis();
        System.out.println(b);
        System.out.println("多线程执行任务1耗时："+(endT-beginT));
    }

    //单线程实现任务1
    public  static void single(){
        long beginS=System.currentTimeMillis();
        int a=0;
        for (int i = 0; i < cout; i++) {
            a++;
        }
        int b=0;
        for (int i = 0; i < cout; i++) {
            b++;
        }
        long endS=System.currentTimeMillis();
        System.out.println("单线程执行人1耗时："+(endS-beginS));
    }

}
